﻿using System;
using NUnit.Framework;

namespace MineSweeperCheater.Test
{
  [TestFixture]
  class TestSetMineInCheatField
  {
    [Test]
    public void GoodCase1()
    {
      const int inputRow = 1;
      const int inputCol = 1;
      var result = new int[5, 8]
                       {
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                       };
      Cheater.SetMineInCheatField(inputRow, inputCol, ref result);

      var expected = new int[5, 8]
                       {
                         {1, 1, 1, 0, 0, 0, 0, 0},
                         {1, 0, 1, 0, 0, 0, 0, 0},
                         {1, 1, 1, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                       };
      Assert.That(result, Is.EqualTo(expected));
    }

    [Test]
    public void GoodCase2()
    {
      const int inputRow = 3;
      const int inputCol = 5;
      var result = new int[5, 8]
                       {
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 1, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                       };
      Cheater.SetMineInCheatField(inputRow, inputCol, ref result);

      var expected = new int[5, 8]
                       {
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 0, 0, 0, 0},
                         {0, 0, 0, 0, 1, 1, 1, 0},
                         {0, 0, 0, 0, 2, 0, 1, 0},
                         {0, 0, 0, 0, 1, 1, 1, 0},
                       };
      Assert.That(result, Is.EqualTo(expected));
    }


    int _inputRow;
    int _inputCol = 5;
    private int[,] _result;

    public void DelegateExceptionWhenSettingOutsideTheValidRange()
    {
      Cheater.SetMineInCheatField(_inputRow, _inputCol, ref _result);
    }

    [Test]
    public void ExceptionWhenSettingOutsideTheValidRange1()
    {
      _inputRow = 0;
      _inputCol = 0;
      _result = new int[5, 8]
                     {
                       {0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 1, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0},
                     };

      Assert.Throws<IndexOutOfRangeException>(DelegateExceptionWhenSettingOutsideTheValidRange);
    }

    [Test]
    public void ExceptionWhenSettingOutsideTheValidRange2()
    {
      _inputRow = -3;
      _inputCol = 4;
      _result = new int[5, 8]
                     {
                       {0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 1, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0},
                     };

      Assert.Throws<IndexOutOfRangeException>(DelegateExceptionWhenSettingOutsideTheValidRange);
    }

    [Test]
    public void ExceptionWhenSettingOutsideTheValidRange3()
    {
      _inputRow = 3;
      _inputCol = 7;
      _result = new int[5, 8]
                     {
                       {0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 1, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0},
                     };

      Assert.Throws<IndexOutOfRangeException>(DelegateExceptionWhenSettingOutsideTheValidRange);
    }
  }
}
